/**
 * Project Name:fastPlat
 * File Name:SiteMsgServiceImpl.java
 * Package Name:com.fast.cms.service.article.impl
 * Date:2017年05月27日 13时58分27秒
 * Copyright (c) 2017, lsflu@126.com All Rights Reserved.
 *
*/

package com.fast.cms.service.article.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.fast.base.dao.daoSuport.JpaDaoSupport;
import com.fast.base.db.page.PageView;
import com.fast.base.db.page.QueryResult;
import com.fast.cms.model.article.SiteMsg;
import com.fast.cms.service.article.SiteMsgService;
import com.fast.cms.web.form.SiteMsgForm;

/**
 * ClassName:SiteMsgServiceImpl <br/>
 * 用途: 站内信服务实现 <br/>
 * 开发人员：lushuifa  http://lushuifa.iteye.com/
 * 邮箱:lsflu@126.com
 * @version  1.0
 * @since    JDK 1.6
 * @see
 * Date:     2017年05月27日 13时58分27秒 <br/> 	 
 */
@Service("siteMsgService")
public class SiteMsgServiceImpl extends JpaDaoSupport implements SiteMsgService {

    /**
	 * 分页获取站内信列表
	 * @return PageView<SiteMsg>
	 */
	@Override
	public PageView<SiteMsg> getSiteMsgList(SiteMsgForm siteMsgForm){
		StringBuffer sb = new StringBuffer(" where 1=1 ");
		if(StringUtils.equals(siteMsgForm.getQueryType(), "my")){
			sb.append("and reciveAdminArr like '%"+siteMsgForm.getReciveAdminArr()+"%' ");
		}
		
		if(StringUtils.isNotBlank(siteMsgForm.getIsRead())){
			sb.append("and isread="+siteMsgForm.getIsRead()+" ");
		}
		sb.append("and delete_flag="+siteMsgForm.getDeleteFlag()+" ");
		String ordersql = " order by edit_time desc ";
		QueryResult<SiteMsg>  queryResult = super.queryForBeanListByPage(SiteMsg.class,sb.toString(),ordersql,(siteMsgForm.getPage()-1)*siteMsgForm.getRows(),siteMsgForm.getRows());
		PageView<SiteMsg> pageView = new PageView<SiteMsg>();
	    pageView.setCurrentPage(siteMsgForm.getPage());
		pageView.setQueryResult(queryResult);
 		return pageView;
	}
	
	/**
	 * 查询消息列表
	 * @return
	 */
	public List<Map<String, Object>> getSiteMsgListLimit15(String reciveAdminArr,String recivePositionArr){
		List<Map<String, Object>> mapList = new ArrayList<Map<String, Object>>();
		try {
			Map<String,Object> paramMap = new HashMap<String,Object>();
			paramMap.put("limit", 15);
			paramMap.put("reciveAdminArr", reciveAdminArr);
			paramMap.put("recivePositionArr", recivePositionArr);
			mapList = super.getSession().selectList("siteMsg.getSiteMsgListLimit",paramMap);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return mapList;
	}
	
}

